﻿cmake_minimum_required(VERSION 3.5)

set(CMAKE_CXX_STANDARD 17)
project(guild-service)

IF (MSVC)
ELSE()
  SET(CMAKE_CXX_FLAGS "-m64 -g -O2 -std=c++17 -Wall -Wno-unused-variable -fnon-call-exceptions")
  set(CMAKE_CXX_COMPILER "g++")
ENDIF()

include_directories(
    ${PROJECT_SOURCE_DIR}/../../../../..
    ${PROJECT_SOURCE_DIR}/../../../../../../thirdparty/include
    ${PROJECT_SOURCE_DIR}/../../../../src/include/root
    ${PROJECT_SOURCE_DIR}/../../../../thirdparty/include
)

aux_source_directory(. SRC_FILES)

if(WIN32)
	message("WIN32")
    link_directories(${PROJECT_SOURCE_DIR}/../../../../../../win-proj/x64/Debug) #service-box.lib
else()
    message("LINUX")
    link_directories(${PROJECT_SOURCE_DIR}/../../../../../lib) #libservice_box.a
    link_directories(${PROJECT_SOURCE_DIR}/../../../../lib/root) #librpc.a
    link_directories(${PROJECT_SOURCE_DIR}/../../../../thirdparty/lib/linux) #libprotobuf.a
    link_directories(/usr/local/lib) #libhiredis.a libz.a libcurl.a libhashtable.a libzookeeper.a
endif()

add_executable (${PROJECT_NAME} ${SRC_FILES})

#静态链接库目录
if (MSVC)
	message("WIN32")
foreach(var
  CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE
  CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELWITHDEBINFO
  CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE
  CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO
)
if(${var} MATCHES "/MD")
  string(REGEX REPLACE "/MD" "/MT" ${var} "${${var}}")
endif()
endforeach()
    set_target_properties(${PROJECT_NAME} PROPERTIES COMPILE_FLAGS "/EHsc /W3")

    SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES LINK_FLAGS_DEBUG " 
    /WHOLEARCHIVE:${PROJECT_SOURCE_DIR}/../../../../lib/guildservicebasic/Debug/libguildservicebasic.a
    /WHOLEARCHIVE:${PROJECT_SOURCE_DIR}/../../../../lib/guildservicequery/Debug/libguildservicequery.a
    /WHOLEARCHIVE:${PROJECT_SOURCE_DIR}/../../../../lib/guildservicewelfare/Debug/libguildservicewelfare.a
    /WHOLEARCHIVE:${PROJECT_SOURCE_DIR}/../../../../lib/guildserviceauth/Debug/libguildserviceauth.a
    /WHOLEARCHIVE:${PROJECT_SOURCE_DIR}/../../../../lib/guildservicetimer/Debug/libguildservicetimer.a
    /WHOLEARCHIVE:${PROJECT_SOURCE_DIR}/../../../../lib/guildservicebuilding/Debug/libguildservicebuilding.a
    /WHOLEARCHIVE:${PROJECT_SOURCE_DIR}/../../../../lib/guildservicerank/Debug/libguildservicerank.a
    /WHOLEARCHIVE:${PROJECT_SOURCE_DIR}/../../../../lib/guildservicechat/Debug/libguildservicechat.a
    /WHOLEARCHIVE:${PROJECT_SOURCE_DIR}/../../../../lib/guildservicetask/Debug/libguildservicetask.a
    /WHOLEARCHIVE:${PROJECT_SOURCE_DIR}/../../../../lib/guildserviceactivity/Debug/libguildserviceactivity.a
    /WHOLEARCHIVE:${PROJECT_SOURCE_DIR}/../../../../lib/stub/guildservicebasic/GuildServiceBasic/Debug/libGuildServiceBasic_stub.a 
    /WHOLEARCHIVE:${PROJECT_SOURCE_DIR}/../../../../lib/stub/guildservicequery/GuildServiceQuery/Debug/libGuildServiceQuery_stub.a
    /WHOLEARCHIVE:${PROJECT_SOURCE_DIR}/../../../../lib/stub/guildservicewelfare/GuildServiceWelfare/Debug/libGuildServiceWelfare_stub.a
    /WHOLEARCHIVE:${PROJECT_SOURCE_DIR}/../../../../lib/stub/guildserviceauth/GuildServiceAuth/Debug/libGuildServiceAuth_stub.a
    /WHOLEARCHIVE:${PROJECT_SOURCE_DIR}/../../../../lib/stub/guildservicetimer/GuildServiceTimer/Debug/libGuildServiceTimer_stub.a
    /WHOLEARCHIVE:${PROJECT_SOURCE_DIR}/../../../../lib/proxy/guildservicewelfare/GuildClientWelfare/Debug/libGuildClientWelfare_proxy.a
    /WHOLEARCHIVE:${PROJECT_SOURCE_DIR}/../../../../lib/stub/guildservicebuilding/GuildServiceBuilding/Debug/libGuildServiceBuilding_stub.a
    /WHOLEARCHIVE:${PROJECT_SOURCE_DIR}/../../../../lib/stub/guildservicerank/GuildServiceRank/Debug/libGuildServiceRank_stub.a
    /WHOLEARCHIVE:${PROJECT_SOURCE_DIR}/../../../../lib/stub/guildservicechat/GuildServiceChat/Debug/libGuildServiceChat_stub.a
    /WHOLEARCHIVE:${PROJECT_SOURCE_DIR}/../../../../lib/stub/guildservicetask/GuildServiceTask/Debug/libGuildServiceTask_stub.a
    /WHOLEARCHIVE:${PROJECT_SOURCE_DIR}/../../../../lib/stub/guildserviceactivity/GuildServiceActivity/Debug/libGuildServiceActivity_stub.a
    /WHOLEARCHIVE:${PROJECT_SOURCE_DIR}/../../../../lib/proxy/guildservicetimer/GuildServiceTimer/Debug/libGuildServiceTimer_proxy.a
    ")
    
    SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES LINK_FLAGS_RELEASE " 
    /WHOLEARCHIVE:${PROJECT_SOURCE_DIR}/../../../../lib/guildservicebasic/Release/libguildservicebasic.a 
    /WHOLEARCHIVE:${PROJECT_SOURCE_DIR}/../../../../lib/guildservicetimer/Release/libguildservicetimer.a 
    /WHOLEARCHIVE:${PROJECT_SOURCE_DIR}/../../../../lib/guildservicequery/Release/libguildservicequery.a 
    /WHOLEARCHIVE:${PROJECT_SOURCE_DIR}/../../../../lib/guildserviceauth/Release/libguildserviceauth.a 
    /WHOLEARCHIVE:${PROJECT_SOURCE_DIR}/../../../../lib/guildservicewelfare/Release/libguildservicewelfare.a 
    /WHOLEARCHIVE:${PROJECT_SOURCE_DIR}/../../../../lib/guildservicebuilding/Release/libguildservicebuilding.a
    /WHOLEARCHIVE:${PROJECT_SOURCE_DIR}/../../../../lib/guildservicerank/Release/libguildservicerank.a
    /WHOLEARCHIVE:${PROJECT_SOURCE_DIR}/../../../../lib/guildservicechat/Release/libguildservicechat.a
    /WHOLEARCHIVE:${PROJECT_SOURCE_DIR}/../../../../lib/guildservicetask/Release/libguildservicetask.a
    /WHOLEARCHIVE:${PROJECT_SOURCE_DIR}/../../../../lib/guildserviceactivity/Release/libguildserviceactivity.a
    /WHOLEARCHIVE:${PROJECT_SOURCE_DIR}/../../../../lib/stub/guildservicebasic/GuildServiceBasic/Release/libGuildServiceBasic_stub.a 
    /WHOLEARCHIVE:${PROJECT_SOURCE_DIR}/../../../../lib/stub/guildservicequery/GuildServiceQuery/Release/libGuildServiceQuery_stub.a
    /WHOLEARCHIVE:${PROJECT_SOURCE_DIR}/../../../../lib/stub/guildservicewelfare/GuildServiceWelfare/Release/libGuildServiceWelfare_stub.a
    /WHOLEARCHIVE:${PROJECT_SOURCE_DIR}/../../../../lib/stub/guildserviceauth/GuildServiceAuth/Release/libGuildServiceAuth_stub.a
    /WHOLEARCHIVE:${PROJECT_SOURCE_DIR}/../../../../lib/stub/guildservicetimer/GuildServiceTimer/Release/libGuildServiceTimer_stub.a
    /WHOLEARCHIVE:${PROJECT_SOURCE_DIR}/../../../../lib/proxy/guildservicewelfare/GuildClientWelfare/Release/libGuildClientWelfare_proxy.a
    /WHOLEARCHIVE:${PROJECT_SOURCE_DIR}/../../../../lib/stub/guildservicebuilding/GuildServiceBuilding/Release/libGuildServiceBuilding_stub.a
    /WHOLEARCHIVE:${PROJECT_SOURCE_DIR}/../../../../lib/stub/guildservicerank/GuildServiceRank/Release/libGuildServiceRank_stub.a
    /WHOLEARCHIVE:${PROJECT_SOURCE_DIR}/../../../../lib/stub/guildservicechat/GuildServiceChat/Release/libGuildServiceChat_stub.a
    /WHOLEARCHIVE:${PROJECT_SOURCE_DIR}/../../../../lib/stub/guildservicetask/GuildServiceTask/Release/libGuildServiceTask_stub.a
    /WHOLEARCHIVE:${PROJECT_SOURCE_DIR}/../../../../lib/stub/guildserviceactivity/GuildServiceActivity/Release/libGuildServiceActivity_stub.a
    /WHOLEARCHIVE:${PROJECT_SOURCE_DIR}/../../../../lib/proxy/guildservicetimer/GuildServiceTimer/Release/libGuildServiceTimer_proxy.a
    ")
    
    target_link_libraries(${PROJECT_NAME}
        service-box.lib
        ${PROJECT_SOURCE_DIR}/../../../../lib/root/Debug/librpc.a
        ${PROJECT_SOURCE_DIR}/../../../../thirdparty/lib/windows/debug/libprotobufd.lib
        ${PROJECT_SOURCE_DIR}/../../../../thirdparty/lib/windows/release/libprotobuf.lib
        ${PROJECT_SOURCE_DIR}/../../../../../../thirdparty/lib/win/Debug/zookeeper.lib
        ${PROJECT_SOURCE_DIR}/../../../../../../thirdparty/lib/win/Debug/hashtable.lib
        ${PROJECT_SOURCE_DIR}/../../../../../../thirdparty/lib/win/Debug/hiredis.lib
        ${PROJECT_SOURCE_DIR}/../../../../../../thirdparty/lib/win/Debug/Win32_Interop.lib
        ${PROJECT_SOURCE_DIR}/../../../../../../thirdparty/lib/win/Debug/libcurl.a
        # libz.a

        wldap32.lib
        ws2_32.lib
        psapi.lib
    )
ELSE()
    message("LINUX")
    target_link_libraries(${PROJECT_NAME}
        libservice_box.a
        librpc.a
        libprotobuf.a
        libzookeeper.a
        libhashtable.a
        libhiredis.a
        libcurl.a
        libz.a
        -lpthread
        -ldl
        -Wl,--whole-archive
        ${PROJECT_SOURCE_DIR}/../../../../lib/guildservicebasic/libguildservicebasic.a
        ${PROJECT_SOURCE_DIR}/../../../../lib/guildservicequery/libguildservicequery.a
        ${PROJECT_SOURCE_DIR}/../../../../lib/guildservicewelfare/libguildservicewelfare.a
        ${PROJECT_SOURCE_DIR}/../../../../lib/guildserviceauth/libguildserviceauth.a
        ${PROJECT_SOURCE_DIR}/../../../../lib/guildservicetimer/libguildservicetimer.a
        ${PROJECT_SOURCE_DIR}/../../../../lib/guildservicebuilding/libguildservicebuilding.a
        ${PROJECT_SOURCE_DIR}/../../../../lib/guildservicerank/libguildservicerank.a
        ${PROJECT_SOURCE_DIR}/../../../../lib/guildservicechat/libguildservicechat.a
        ${PROJECT_SOURCE_DIR}/../../../../lib/guildservicetask/libguildservicetask.a
        ${PROJECT_SOURCE_DIR}/../../../../lib/guildserviceactivity/libguildserviceactivity.a
        ${PROJECT_SOURCE_DIR}/../../../../lib/stub/guildservicebasic/GuildServiceBasic/libGuildServiceBasic_stub.a 
        ${PROJECT_SOURCE_DIR}/../../../../lib/stub/guildservicequery/GuildServiceQuery/libGuildServiceQuery_stub.a
        ${PROJECT_SOURCE_DIR}/../../../../lib/stub/guildservicewelfare/GuildServiceWelfare/libGuildServiceWelfare_stub.a
        ${PROJECT_SOURCE_DIR}/../../../../lib/stub/guildserviceauth/GuildServiceAuth/libGuildServiceAuth_stub.a
        ${PROJECT_SOURCE_DIR}/../../../../lib/stub/guildservicetimer/GuildServiceTimer/libGuildServiceTimer_stub.a
        ${PROJECT_SOURCE_DIR}/../../../../lib/proxy/guildservicewelfare/GuildClientWelfare/libGuildClientWelfare_proxy.a
        ${PROJECT_SOURCE_DIR}/../../../../lib/stub/guildservicetimer/GuildServiceBuilding/libGuildServiceBuilding_stub.a
        ${PROJECT_SOURCE_DIR}/../../../../lib/stub/guildservicetimer/GuildServiceRank/libGuildServiceRank_stub.a
        ${PROJECT_SOURCE_DIR}/../../../../lib/stub/guildservicetimer/GuildServiceChat/libGuildServiceChat_stub.a
        ${PROJECT_SOURCE_DIR}/../../../../lib/stub/guildservicetimer/GuildServiceTask/libGuildServiceTask_stub.a
        ${PROJECT_SOURCE_DIR}/../../../../lib/stub/guildservicetimer/GuildServiceActivity/libGuildServiceActivity_stub.a
        -Wl,--no-whole-archive
    )
ENDIF()